package com.coai.rtc.controller

import com.coai.rtc.model.SignalingMessage
import com.coai.rtc.model.SignalingType
import com.coai.rtc.service.SignalingService
import org.springframework.messaging.handler.annotation.MessageMapping
import org.springframework.messaging.handler.annotation.Payload
import org.springframework.messaging.simp.annotation.SendToUser
import org.springframework.stereotype.Controller
import java.security.Principal

/**
 * WebRTC信令控制器
 */
@Controller
class SignalingController(
    private val signalingService: SignalingService
) {
    
    /**
     * 处理WebRTC Offer
     */
    @MessageMapping("/rtc/offer")
    fun handleOffer(@Payload message: SignalingMessage, principal: Principal) {
        signalingService.handleOffer(message.copy(from = principal.name))
    }
    
    /**
     * 处理WebRTC Answer
     */
    @MessageMapping("/rtc/answer")
    fun handleAnswer(@Payload message: SignalingMessage, principal: Principal) {
        signalingService.handleAnswer(message.copy(from = principal.name))
    }
    
    /**
     * 处理ICE候选
     */
    @MessageMapping("/rtc/ice-candidate")
    fun handleIceCandidate(@Payload message: SignalingMessage, principal: Principal) {
        signalingService.handleIceCandidate(message.copy(from = principal.name))
    }
}
